<template>
  <div class="app-container">
  <div class="filter-container">
        <el-button type="primary" @click="refreshClick()">刷新</el-button>
        <el-input clearable v-model="search.number" placeholder="车牌号码" style="width: 170px;margin-left:10px;"></el-input>
        <el-input clearable v-model="search.name" placeholder="联系人" style="width: 170px;margin-left:10px;"></el-input>
        <el-input clearable v-model="search.phone" placeholder="联系电话" style="width: 170px;margin:0 5px;"></el-input>
        <el-date-picker v-model="search.daterange" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>

        <el-button type="primary" icon="el-icon-search" @click="searchClick()" style="margin-left:10px;">查询</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" 
      border fit highlight-current-row stripe 
      style="width: 100%">
      <el-table-column align="center" label="序" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row._id }}</span>
        </template>
      </el-table-column>
     <el-table-column  min-width="100" align="center" label="车牌号码">
        <template slot-scope="scope">
          <span>{{ scope.row.licenseplate }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="具体车型">
        <template slot-scope="scope">
          <span>{{ scope.row.carname }}</span>
        </template>
      </el-table-column>
      
      <el-table-column  min-width="100" align="center" label="车身颜色">
        <template slot-scope="scope">
          <span>{{ scope.row.carcolor }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="是否本店购买">
        <template slot-scope="scope">
          <span>{{ scope.row.buyinshop }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="客户姓名">
        <template slot-scope="scope">
          <span>{{ scope.row.customername }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="联系电话">
        <template slot-scope="scope">
          <span>{{ scope.row.customerphone }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="出厂日期">
        <template slot-scope="scope">
          <span>{{ scope.row.productiondate }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="维修类别">
        <template slot-scope="scope">
          <span>{{ scope.row.repairtype }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="是否保养">
        <template slot-scope="scope">
          <span>{{ scope.row.keepfit}}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="接车员">
        <template slot-scope="scope">
          <span>{{ scope.row.taker }}</span>
        </template>
      </el-table-column>
      
      <el-table-column  min-width="100" align="center" label="状态">
        <template slot-scope="scope">
          <span>{{ scope.row.state }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="备注">
        <template slot-scope="scope">
          <span>{{ scope.row.remark }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="日期">
        <template slot-scope="scope">
          <span>{{ scope.row.createtime | parseTime('{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="操作"  width="120" fixed="right">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="rowAllocateClick(scope.row.id)">分配</el-button>
          
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.rows" @pagination="fetchData" />

<!-- 分配 -->
<el-dialog :title="dialog.title" :visible.sync="dialog.visible"  width="700px">
    <div class="ci">
        <div class="item">
        <span class="name required">接单人</span>
        <span class="value">
            <el-select v-model="dialog.data.taker" clearable placeholder="--" style="width: 220px;">
                <el-option 
                v-for="(item,index) in selectOptions.takers"
                :key="index"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select>
            
        </span>
        </div>
        
    </div>
    <div slot="footer" class="dialog-footer">
        <el-button @click="dialog.visible = false">取 消</el-button>
        <el-button type="primary" @click="saveAllocateClick()" :loading="dialog.saveloading">保 存</el-button>
    </div>
</el-dialog>
<!-- end 分配 -->


  </div>
</template>

<script>
import * as allocateApi from '@/api/aftersale/allocate'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import * as enumHelper from '@/utils/enum'

export default {
  name:'carlist1',
    components: { Pagination },
    data(){
        return{
          search:{ 
              number:'',
              customer:'',
              phone:'',
              daterange:'',
          },
          listQuery: {
                page: 1,
                rows: 20,
                name:'',
                phone:'',
                state:-1,
                daterange:''
          },
          list:null,
          listLoading:false,
          total:0,
          selectOptions:{
            takers:[]
          },

          dialog:{
              visible:false,
              saveloading:false,
              title:'分配',
              data:{
                  id:'',
                  taker:''
              }
          },
          
        }
    },
    created(){
        var that=this;
        //初始化下拉菜单
        //enumHelper.initOptions(that.selectOptions.salesState,enumHelper.presale.salesState);
        that.fetchData();
    },
    filters:{
      parseHandingType(val){
        return ['无','已办理','未办理'][val];
      },
      parsePayType(val){
        return enumHelper.presale.payType.getName(val);
      },
      parseSalesState(val){
        return enumHelper.presale.salesState.getName(val);
      }

    },
    methods:{
        fetchData(){
          var that=this;
            allocateApi.getCarlist({}).then(res=>{
              if(res.data){
                that.list=[...res.data.items.map((item,index)=>{
                  item._id=index+1;
                  return item;
                })];
              }
            })
        },
        refreshClick(){
          this.fetchData();
        },
        
        saveAllocateClick(){
          var that=this;
          that.dialog.saveloading=true;
        },
        rowAllocateClick(id){
          var that=this;
          that.dialog.visible=true;

          
        }
    }
}
</script>

<style>

</style>